<?php
namespace Home\Controller;
use Think\Controller;
class ReleaseController extends CommonController {
  public function index(){
    $m = M("cate");
    $map['fid'] = array('gt',0);
    $typeList = $m->where($map)->select(); 
    $this->assign("typeList",$typeList);
    // var_dump($typeList);
    $m = M("cate");
    $cateList1 = $m->where('fid = 1')->select();
    $cateList2 = $m->where('fid = 2')->select();
    $this->assign('cateList1',$cateList1);
    $this->assign('cateList2',$cateList2);

    $this->display();
  }

  public function release(){
    $m = M("info");
    $data = $m->create();
    $data['ctime']=time();
    $upload = new \Think\Upload();// 实例化上传类
    $upload->maxSize   =     3145728 ;// 设置附件上传大小 2M = 1024*1024*2=2097152 3M = 1024*1024*3=3145728
    $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
    $upload->rootPath  =      './Public/img/info_ico/'; // 设置附件上传目录    // 上传文件
    $info   =   $upload->uploadOne($_FILES['pic']);
    if(!$info) {// 上传错误提示错误信息
      $this->error($upload->getError());
    }else{// 上传成功
      $data['picurl']=$info['savepath'].$info['savename'];
      $data['intro']=$_POST['intro'];
      $data['ip_name']=$_POST['name'];
      $data['typeid']=$_POST['typeid'];
      $data['phone']=$_POST['phone'];
      $data['price']=$_POST['price'];
      $data['author_nickname']=$_SESSION['nickname'];
      $result = $m->add($data);      
      if($result>0){
          $this->success("发布成功！");
      }else{
          $this->error("发布失败！");      
      }
    }
  }


}
